package com.czxy.changgou3.com.czxy.changgou3.controller;

import com.czxy.changgou3.com.czxy.changgou3.service.SkuService;
import com.czxy.changgou3.vo.ESData;
import com.czxy.changgou3.vo.OneSkuResult;
import com.czxy.vo.BaseResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zhangmengxiang1@itcast.cn
 * @version 1.0
 * @date 2020/4/23
 */
@RestController
@RequestMapping("/sku")
public class SkuController {

    @Resource
    private SkuService skuService;

    @GetMapping("/esData")
    public BaseResult<List<ESData>> findAll(){
        //查询
        List<ESData> list = skuService.findAllSku();
        //返回
        return BaseResult.ok("查询成功" , list );
    }

    /**
     * 查询详情
     * @param skuId
     * @return
     */
    @GetMapping("/goods/{skuId}")
    public BaseResult<OneSkuResult> findById(@PathVariable("skuId") Integer skuId){
        //查询
        OneSkuResult oneSkuResult = skuService.findSkuById(skuId);
        //返回
        return BaseResult.ok("查询成功",oneSkuResult);
    }

    /**
     * 更新
     * @param skuid
     * @param count
     * @return
     */
    @PutMapping("/goods/{skuid}")
    public BaseResult updateSkuNum(@PathVariable("skuid") Integer skuid,
                                   @RequestParam("count") Integer count){
        skuService.updateSkuNum(skuid,count);
        return BaseResult.ok("更新成功");
    }

}
